<template>
  <div :class="['specialistQusAndAns', hideHeader ? 'hideHeaderTop' : '']">
    <div class="first-words" ref="tabe" :style="stySty">页面数据加载成功</div>
    <div v-if="!noData">
      <scroller ref='scrollerBottom' style="top: 0.88rem;" :on-refresh="refresh" :on-infinite="infinite"  class="my-scroller">
        <div class="scrollerDiv">
          <!-- 专家问答 -->
          <ul class="questionList">
            <li class="questionItem" v-for="(item, index) of questionLists" :key="index" @click="jumpIntoQuestions(item.questionId)">
              <p class="question_time">{{ (new Date(item.createTime)).format('yyyy-MM-dd hh:mm') }} 提问</p>
              <div class="question_title">{{ item.title }}</div>
              <div class="imageList">
                <div class="imageShowItem" v-for="(n, m) of item.pictures" :key="m">
                  <img :src="n" alt="">
                </div>
              </div>
              <div class="bottom">
                <span>{{ item.questionType }}</span>
                <span v-if="!item.answerList || item.answerList.length == 0">暂无回答</span>
                <span v-else>{{ '有' + item.answerList.length + '条回答'}}</span>
              </div>
            </li>
          </ul>
          <!-- 院校答疑 -->
          <!-- <ul class="questionList">
            <li class="questionItem" v-for="(item, index) of schoolsLists" :key="index" @click="jumpIntoSchools(item.id)">
              <p class="question_time">{{ (new Date(item.createTime)).format('yyyy-MM-dd hh:mm') }} 提问</p>
              <div class="question_title">{{ item.title }}</div>
              <div class="bottom">
                <span>{{ item.academyName }}</span>
                <span v-if="item.number == 0">暂无回答</span>
                <span v-else>{{ '有' + item.number + '条回答'}}</span>
              </div>
            </li>
          </ul> -->
        </div>
        <div style="width: 7.5rem;height: 0.5rem;"></div>
      </scroller>
    </div>
    <div v-else>
      <div class="noDataImage">
        <img src="~/static/nothing/empty_ask.png" alt="">
        <div class="describe">您还没有提问，赶紧来提问吧</div>
        <div class="fixed-btn" @click="commonJs.gopush('../curriculum/putQuestions')">向TA提问</div>
      </div>
    </div>
  </div>
</template>

<script>
import { professorHomePage } from "~/api/identity";
import { format } from '~/plugins/filter';
export default {
  data() {
    return {
      stySty: "",
      noData: true,
      questionLists: [],
      listData: [],
      questionParams: {
        pageNo: 1,
        pageSize: 10,
        questionType: 1
      },
      onFetching: true,
      currentPage:1,
      hideHeader: false
    }
  },
  created() {
    if (this.commonJs.GetUrlParam('mini_token')) {
      this.hideHeader = true
    }
  },
  mounted() {
    this.$visit(this.$route.path)
    this.$loading('open');
    this.getQuestionList()
    this.$store.commit("changeexpertId", null);
    this.$store.commit("changeexpertName", null);
  },
  methods: {
    refresh(done) {
      setTimeout(() => {
        this.questionParams.pageNo = 1;
        this.getQuestionList()
        this.stySty = "z-index:10000;opacity: 1;";
        let _this = this;
        setTimeout(() => {
          _this.stySty = "z-index:-1;opacity: 0;";  
        }, 2000);
        done()
      },1000)
    },
    getQuestionList() {
      professorHomePage(this.questionParams).then(res => {
        if (res.code == 0) {
          const data = res.data;
          this.questionLists = data.qaPageInfo.list || [];
          this.totlaPages =Math.ceil(data.qaPageInfo.total/this.questionParams.pageSize);
          if (this.questionLists.length == 0) {
            this.noData = true
          } else {
            this.noData = false
          }

        } else {
          this.$vux.toast.text('网络故障，请稍后再试~');
        }
      }).catch(error => {
        this.$vux.toast.text('网络故障，请稍后重试~');
      }).finally(() => {
           this.$hideLoading();
      })
    },


    infinite(done) {
      if (this.currentPage < this.totlaPages) {
        this.currentPage = this.currentPage + 1;
        professorHomePage({
          pageNo: this.currentPage,
          pageSize: 10,
          questionType: 1

        }).then(res => {
          if (res.code == "0") {
            const data = res.data;
            let newArr  = data.qaPageInfo.list;
            
            this.questionLists = this.questionLists.concat(newArr);
            this.totlaPages =Math.ceil(data.qaPageInfo.total/this.questionParams.pageSize);
   
            done();
          }
        });
      } else {
        done(true);
        return;
      }
    },
    jumpIntoQuestions(id) {
      if (this.commonJs.GetUrlParam('mini_token')) {
        this.$router.push({
          path: '../curriculum/questionDetail',
          query: {
            qid: id,
            mini_token: this.commonJs.GetUrlParam('mini_token')
          }
        });
      } else {
        this.goto('../curriculum/questionDetail', id);
      }
    },
    goto(routerName, queryData) {
      this.$router.push({
        path: routerName,
        query: {
          qid: queryData
        }
      });
    },
  }
}
</script>

<style lang="less" scoped>
 .first-words {
    width: 100%;
    height:  0.8rem;
    background: #ffad0d;
    position: absolute;
    z-index: -1;
    opacity: 0;
    text-align: center;
    line-height: 0.8rem;
    font-size: 0.3rem;
    color: #fff;
    left: 0;
    top: 1.9rem;
  }
  .specialistQusAndAns {

    /deep/ .pull-to-refresh-layer {
      margin-top: -0.15rem !important;
    }

    .scrollerDiv {
      padding: 0rem 0.35rem 0 0.29rem;

      .questionList {
        padding-left: 0;
        list-style: none;

        .questionItem {
          width: 100%;
          padding: 0.32rem 0;
          border-bottom: 1px solid #E5E8ED;

          .question_time {
            color: #999;
            font-size: 0.26rem;
            line-height: 0.44rem;
            margin-bottom: 0.14rem;
          }

          .question_title {
            color: #222;
            font-size: 0.3rem;
            line-height: 0.48rem;
            font-weight: bold;
            margin-bottom: 0.16rem;
          }

          .imageList {
            display: flex;
            justify-content: flex-start;
            align-items: center;
            flex-wrap: wrap;
            margin-bottom: 0.26rem;

            .imageShowItem {
              width: 1rem;
              height: 1rem;
              margin-right: 0.24rem;
              img {
                width: 100%;
                height: 100%;
              }
            }

          }

          .bottom {
            display: flex;
            justify-content: space-between;
            align-items: center;

            span {
              color: #999;
              font-size: 0.26rem;
              line-height: 0.44rem;
            }

          }

        }

      }

    }

    .noDataImage {
      text-align: center;
      padding-top: 2.4rem;
      img {
        width: 2.4rem;
        height: 2.4rem;
        margin-bottom: 0.24rem;
      }
      .describe {
        color: #999;
        font-size: 0.28rem;
        line-height: 0.4rem;
        margin-bottom: 0.2rem;
      }
      .fixed-btn {
        width: 2.6rem;
        height: 0.88rem;
        background: @assistColor;
        box-shadow: 0px 0.08rem 0.2rem 0px rgba(128, 213, 102, 0.3);
        border-radius: 0.44rem;
        text-align: center;
        line-height: 0.88rem;
        font-size: 0.3rem;
        font-weight: 600;
        margin: 0 auto;
        color: rgba(255, 255, 255, 1);
      }
    }
  }
  .hideHeaderTop {
    /deep/ .pull-to-refresh-layer {
      margin-top: -60px !important;
    }
  }
</style>